import common from '@/utils/common'
import request from '@/utils/requestutil'
const state = {
  dic: {},
  dicSelect: {}
}
const mutations = {
  setDicInfo(key, data) {
    state.dic[data.key] = data.data;
  },
  setDicSelectInfo(key, data) {
    state.dicSelect[data.key] = data.data;
  }
}
const actions = {
  loaddic: async function (dickey) {
    let s= await request({
      url: this.$root.$options.baseHttpurl + '/dic/initdic',
      method: 'get',
      params: {
        'key': param.key
      }
    });
    console.log(s);
     return s;// state.dic[dickey]=s;
  },
  getText:async function ({commit }, param) {
    let url = common.baseHttpurl + '/dic/initdic';
    return new Promise(async resolve => {
      if (state.dic[param.key] == undefined) {
        let s= await request({
          url: url,
          method: 'get',
          params: {
            'key': param.key
          }
        });
       let data=s;
       commit("setDicInfo",{key:param.key,data:data})
      }
      // debugger
      resolve( {text:state.dic[param.key][param.id]}) ;
    });
  },

  getSelect:async function ({commit}, param) {
    let url = common.baseHttpurl + '/dic/dicselectList';
    return new Promise(async resolve => {
      if (state.dicSelect[param.key] == undefined) {
        let s= await request({
          url: url,
          method: 'get',
          params: {'key': param.key}
        });
        let data=s.data;
        commit("setDicSelectInfo", {key:param.key,data:data})
      }
      // debugger
      resolve( {selelct:state.dicSelect[param.key]}) ;
    });
  },


}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
